package model

import (
	"github.com/go-xorm/xorm"
	"config"
	_ "github.com/go-sql-driver/mysql"
)

var engine *xorm.Engine

func InitDb(m *config.Mysql) error {
	var err error
	engine , err = xorm.NewEngine("mysql",m.DSN())
	if err != nil {
		return err
	}
	err = engine.Ping()
	if err != nil {
		return err
	}
	engine.SetMaxIdleConns(100)
	engine.SetMaxOpenConns(100)
	engine.Sync2(new(Users))
	engine.ShowExecTime(true)
	engine.ShowSQL(true)
	return nil
}
